package com.service.impl;

import com.dao.impl.OrderImpl;
import com.dao.impl.opMenuImpl;
import com.entity.Trolley;
import com.service.opMenuService;
import com.entity.Menus;
import com.entity.OrderStatus;

import java.util.List;

import static com.util.Vessel.*;

public class opMenuSerImpl implements opMenuService {

    //查看菜单
    @Override
    public void vsMenusService() {
        List<Menus> menusList = opMenu.vsMenus();
        System.out.println("菜品编号" + "\t\t" + "菜品名称" +"\t\t\t" + "菜品价格");
        for (Menus menus : menusList ){
            System.out.println(menus.getmId() + "\t\t\t" + menus.getmName() +"\t\t\t" + menus.getePrice());
        }
    }

    //加购
    @Override
    public void orderMeService(int cId,int tId) {
        boolean isFlag = false;
        boolean isNext = false;
        do {
            System.out.println("菜单:");
            opMenuSer.vsMenusService();
            System.out.println("请输入菜品编号：");
            int mId = scanner.nextInt();
            int num = opMenu.detect(mId);
            if (num > 0){
                System.out.println("请输入菜品数量：");
                int mNumber = scanner.nextInt();
                if (mNumber <= 0){
                    System.out.println("输入不合法请重新输入");

                }else {
                    opMenu.register(cId,tId,mId,mNumber);//数量合法正常添加
                }
                System.out.println("是否继续加菜:1:是   2:退出");
                int isflag = scanner.nextInt();
                isFlag = (isflag == 1);
            }else {
                System.out.println("输入错误,请重新操作!");
            }
        }while(isFlag);
    }

    //查看餐袋
    @Override
    public void vsMealBag(int cId,int tId) {
        List<Trolley> TrolleyList = opMenu.vsMealBag(cId,tId);
        boolean isnull = opMenu.selectNull(cId,tId);
        if (isnull){
            System.out.println("餐桌编号\t\t" + "菜品编号\t\t\t" + " 菜品名称\t\t\t\t" + "菜品数量\t\t\t" +
                    "菜品单价\t\t" +  "\t单个菜品总价\t\t\t" + "勾选状态");
            for(Trolley trolley : TrolleyList){
                System.out.println(trolley.gettId() + "\t\t\t" + trolley.getmId() + "\t\t\t\t" + trolley.getName() + "\t\t\t\t"+ trolley.getNumber()
                        + "\t\t\t\t" + trolley.getPrice() + "\t\t\t\t"  + trolley.getaPrice() + "\t\t\t" + trolley.getOrderStatus());
            }
        }else {
            System.out.println("餐袋为空!");
        }
    }

    //管理餐袋
    @Override
    public void magMealBag(int cId,int tId) {
        System.out.println("请输入菜品编号:");
        int mId = scanner.nextInt();
        System.out.println("请设置菜品数量:");
        int mNumber = scanner.nextInt();
        int num = opMenu.magMealBag(cId,mId,mNumber,tId);
        if (num > 0){
            System.out.println("操作成功！！！");
        }else {
            System.out.println("操作失败！！！");
        }
    }

    //推荐菜
    @Override
    public void recommendMenus() {
        List<Menus> menusList = opMenu.recommendMenus();
        System.out.println("进入推荐菜:");
        System.out.println("名称\t\t\t" + "价格");
        for (Menus menu : menusList){
            System.out.println(menu.getmName() + "\t\t\t" + menu.getePrice());
        }
    }
}
